<?php
/**
 * [PHPFOX_HEADER]
 */

defined('PHPFOX') or exit('NO DICE!');

/**
 *
 *
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package  		Module_Photo
 * @version 		$Id: category.class.php 3685 2011-12-06 11:16:21Z Miguel_Espinoza $
 */
class Photo_Component_Block_Viewalbums extends Phpfox_Component
{
    /**
     * Class process method wnich is used to execute this component.
     */
    public function process()
    {
        $aCondition = array(
            'pa.user_id='.phpfox::getUserId()
        );
	list($iCnt, $aRows) = phpfox::getService('photo.album')->get($aCondition, 'pa.time_stamp DESC', '', '6');
//        d($aRows);die('sfrhawierawoehrawierawper');
        foreach ($aRows as $iKey => $aRow)
        {	
                if ($aRow['profile_id'] > 0)
                {
                        $aRows[$iKey]['name'] = Phpfox::getPhrase('photo.profile_pictures');
                        $aRows[$iKey]['link'] = Phpfox::permalink('photo.album.profile', $aRow['user_id'], $aRow['user_name']);
                }
                else
                {
                        $aRows[$iKey]['link'] = Phpfox::permalink('photo.album', $aRow['album_id'], $aRow['name']);
                }
                list($iCnt, $aPhoto) = phpfox::getService('photo')->get('p.is_cover=1 AND p.album_id='.$aRow['album_id']);                
                $aRows[$iKey]['cover_photo_id'] = isset($aPhoto[0]['photo_id']) ? $aPhoto[0]['photo_id'] : 0;
        }
        
        $this->template()->assign(array(
//                        'sHeader' => 'Albums',
                        'aAlbums' => $aRows
                )
        );
        return 'block';
    }

    /**
     * Garbage collector. Is executed after this class has completed
     * its job and the template has also been displayed.
     */
    public function clean()
    {
		(($sPlugin = Phpfox_Plugin::get('photo.component_block_category_clean')) ? eval($sPlugin) : false);
    }
}

?>